package edu.gtcfla.km.appmodules.web;

import java.util.Set;

import javax.servlet.http.HttpServletRequest;

import org.apache.shiro.authz.annotation.RequiresUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.vsg.common.i18n.I18nMessageService;
import org.vsg.common.web.json.ListResult;
import org.vsg.security.annotation.RegisterRequestPermissionStrategy;

import edu.gtcfla.km.appmodules.service.UserPermissionService;
import edu.gtcfla.km.appmodules.vo.CurrentUserCategoryPermissionVO;


@Controller
@Lazy
@RequestMapping(edu.gtcfla.km.core.ApplicationConstant.DATA_RERESOURCE)
public class UserPermissionController {

	@Autowired(required=false)
	private UserPermissionService userPermissionService;
	
	@Autowired(required =false)
	private I18nMessageService i18nMessageService;	
	
	private final String modulePath = "/knowledge";	
	
	@RequiresUser
	@RegisterRequestPermissionStrategy(
		value = modulePath+"/curcate_userperms.json",
		skipCheck = true
	)		
	@RequestMapping(value = modulePath+"/curcate_userperms.json")
	public @ResponseBody ListResult accessCurrentUserPermission(HttpServletRequest request) throws Exception {
		Set<CurrentUserCategoryPermissionVO> currentPermission =  userPermissionService.getAllCategoryPermissionFormCurrentUser();

		ListResult lr = new ListResult();
		lr.setRows(currentPermission);
		lr.setResults((int) currentPermission.size());

		return lr;

	}	
	
}
